package com.homedo.odin.solution.enumcode.other;

import com.homedo.core.common.base.dto.Meta;
import com.homedo.core.common.exception.BizException;
import lombok.Getter;

/**
 * @author: zhaoxudong
 * @date: 2018/3/8 15:10
 * @Description: 人气相关枚举
 */
@Getter
public enum PopularityEnum {
    /**
     * 浏览方案
     */
    VisitProduct(1, 1),
    /**
     * 评论
     */
    Comment(2, 2),
    /**
     * 下载
     */
    Download(3, 5),
    /**
     * 访问主页
     */
    VisitHomepage(4, 1);
    /**
     * 增加人气类型
     */
    private Integer type;
    /**
     * 增加人气值
     */
    private Integer score;

    PopularityEnum(Integer type, Integer score) {

        this.type = type;
        this.score = score;
    }

    public static PopularityEnum getPopularityEnum(Integer type) {
        for (PopularityEnum anEnum : PopularityEnum.values()) {
            if (anEnum.getType().equals(type)) {
                return anEnum;
            }
        }
        throw new BizException(Meta.CODE_451.getCode(), "人气值类型不合规");
    }
}
